//
//  TenViewController.m
//  项目二
//
//  Created by rimi on 16/5/13.
//  Copyright © 2016年 objective. All rights reserved.
//

#import "TenViewController.h"

@interface TenViewController ()

@end

@implementation TenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"进度条、计步器";
    self.view.backgroundColor = [UIColor whiteColor];
//    [self initUIProgressView];
    [self initUIStepper];
}
- (void)initUIStepper{
   /**初始化*/
    UIStepper *stepper = [[UIStepper alloc]initWithFrame:CRM(100, 200, 100, 40)];
    /**添加点击事件*/
    [stepper addTarget:self action:@selector(steep:) forControlEvents:UIControlEventValueChanged];
    /**设置最大值最小值*/
    stepper.minimumValue = 0 ;
    stepper.maximumValue = 50;
    /**长按自动加载*/
    stepper.autorepeat = YES;
    /**最大最小循环*/
    stepper.wraps = YES;
    /**设置每次增长值*/
    stepper.stepValue = 1;
    /**设置按键时是否显示每次加的值；如果设为no常按键会加到走好几个步长的值*/
    stepper.continuous = NO;
    [self.view addSubview:stepper];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CRM(50, 50, 200, 50)];
    label.font = [UIFont systemFontOfSize:20];
    label.tag = 100;
    [self.view addSubview:label];
}
#pragma mark -UIStepper
-(void)steep:(UIStepper *)sender{
    UILabel *label = [self.view viewWithTag:100];
    label.text = [NSString stringWithFormat:@"%f",sender.value];
}

-(void)initUIProgressView{
    /**初始化一个进度条*/
    UIProgressView *pv = [[UIProgressView alloc]init];
    pv.frame = CRM(100, 100, 2, 300);
  /**进度值*/
//    pv.progress = 0.9;
    pv.tag = 100;
     pv.progressViewStyle = UIProgressViewStyleBar;
    /**颜色设置*/
   pv.progressTintColor = [UIColor greenColor];
//    pv.trackTintColor = [UIColor redColor];
    /**进度条图片设置*/
//    pv.progressImage = [UIImage imageNamed:@""];
//    pv.trackImage = [UIImage imageNamed:@""];
    /**用时间控制器模拟时间进度条*/
    [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(refresh:) userInfo:nil repeats:YES];
    [self.view addSubview:pv];
}
#pragma mark - 用函数对进度条做试验
-(void)refresh:(NSTimer *)timer{
    UIProgressView *pv = (UIProgressView *)[self.view viewWithTag:100];
    [pv setProgress:pv.progress+0.1 animated:YES];
    if (pv.progress == 1) {
        NSLog(@"%lu",(unsigned long)timer);
        [timer invalidate];
        NSLog(@"%@",timer);
    }
}
#pragma mrak -关键progress属性当前进度值,并且设置是否需要动画
- (void)setProgress:(float)progress animated:(BOOL)animated
{
    
}
@end
